﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class Haro:DestroyableObject
    {
        private Point2D bossPos, haroPos;
        private Character boss, currentTarget;

        public Haro(Character boss, string name,int health, Sprite objectSprite)
            :base(name,health,objectSprite)
        {
            haroPos.x = objectSprite.X + objectSprite.Width / 2;
            haroPos.y = objectSprite.Y + objectSprite.Height / 2;
            this.boss = boss;
            currentTarget = boss;
            invunerable = true;
        }

        public Point2D LoopLines(float xPos, float yPos, Vector v, int i, float multiplier)
        {
            v = Geometry.VectorMultiply(Geometry.UnitVector(v), ((Geometry.VectorMagnitude(v)+1)/10)*i);
            Point2D pos;
            pos.x = v.x + haroPos.x + (Core.Rnd(100) - 50);
            pos.y = haroPos.y + v.y + (Core.Rnd(100) - 50);
            Graphics.DrawLine(Color.Red, xPos, yPos, pos.x, pos.y);
            return pos;
        }


        public void DoAction(GameController gc)
        {
            bossPos.x = boss.ObjectSprite.X + boss.ObjectSprite.Width / 2;
            bossPos.y = boss.ObjectSprite.Y + boss.ObjectSprite.Height / 2;
        }

        public void DrawLines()
        {
            Vector v = Geometry.VectorFromPoints(haroPos, bossPos);
            Point2D pos = LoopLines(haroPos.x, haroPos.y, v, 1, boss.ObjectSprite.X - haroPos.x);
            for (int i = 2; i < 10; i++)
                pos = LoopLines(pos.x, pos.y, v, i, boss.ObjectSprite.X - haroPos.x);           
            Graphics.DrawLine(Color.Blue, pos.x, pos.y, bossPos.x, bossPos.y);
        }

        public override void Draw()
        {
            objectSprite.Draw();
            Text.DrawText(Name, Color.Red, GlobalConst.F10, (int)objectSprite.X + objectSprite.Width / 2 - 50, (int)objectSprite.Y-30);
            Text.DrawText((int)(((float)health / (float)maxHealth) * 100f) + "%", Color.Red, GlobalConst.F10,
                (int)objectSprite.X + objectSprite.Width / 2 - 50, (int)objectSprite.Y - 20);
            Graphics.FillRectangle(Color.Red, (int)objectSprite.X + objectSprite.Width / 2 - 50,
               (int)objectSprite.Y -10, (int)(((float)health / (float)maxHealth) * 100f), 5);
        }

        public void BuffBoss()
        {
            if (Name.Contains("Defense")) boss.StatModifier.DefenseMultiplier -= 0.1f;
            else if (Name.Contains("Rage")) boss.StatModifier.DamageMultiplier += 1f;
            else if (Name.Contains("Speed")) boss.StatModifier.SpeedMultiplier += 4f;
            else if (Name.Contains("Health")) boss.Health += boss.maxHealth/10;
            else if (Name.Contains("Avoidance")) boss.StatModifier.AvoidanceMultiplier -= 0.1f;
        }

        public override void TakeDamage(int damage, GameController gc)
        {
            if (!invunerable && health > 0)
            {
                health -= damage;
                explosion.Draw((int)(objectSprite.X + objectSprite.Width / 2 - explosion.Width / 2), (int)(objectSprite.Y + objectSprite.Height / 2 - explosion.Height / 2));
                explosion.UpdateAnimation();
            }
            if (health <0) health = 0;
        }
    }
}
